﻿using Learun.Util;
using Quartz;
using Quartz.Impl;
using System.Collections.Generic;
using System.Linq;

namespace Learun.Application.Scheduler
{
    public static class BaseScheduler
    {
        //作业调度
        public static IScheduler scheduler = null;
        /// <summary>
        /// 获取作业调度
        /// </summary>
        public static void GetScheduler()
        {
            if (scheduler == null)
            {
                ISchedulerFactory schedf = new StdSchedulerFactory();
            }
        }

        public static void Start()
        {
            GetScheduler();
            scheduler.Start();

            // 取得需要执行的任务
            Job_ScheduleIBLL job_ScheduleIBLL = new Job_ScheduleBLL();
            Pagination paginationobj = new Pagination();
            paginationobj.page = 0;
            paginationobj.rows = 1000;
            var data = job_ScheduleIBLL.GetPageList(paginationobj, "{}");
            // 设置job需要的参数
            if (data != null)
            {
                List<JobInfo> list = data.Where(t=> t.RunStatus == "running").Select(t => new JobInfo
                {
                    JobName = t.JobName,
                    JobGroup = t.JobGroup,
                    CromExpress = t.CromExpress,
                    TaskClass = t.TaskClass,
                }).ToList();
            }
        }
        /// <summary>
        /// 关闭任务调度器
        /// </summary>
        public static void End()
        {
            GetScheduler();
            scheduler.Shutdown(true);
        }
    }
}
